# Maintainer: Eclipse Adoptium Package Maintainers <temurin-dev@eclipse.org>
pkgname=temurin-21
pkgver=21.0.1_p12
# replace _p1 with _1
_pkgver=${pkgver/_p/_}
_pkgverplus=${pkgver/_p/+}
_pkgvername=${_pkgverplus/+/%2B}
pkgrel=0
pkgdesc="Eclipse Temurin 21"
provider_priority=21
url="https://adoptium.net"
arch="aarch64 x86_64"
license="GPL-2.0-with-classpath-exception"
makedepends="
	alsa-lib-dev
	freetype-dev
	libffi-dev
	libjpeg-turbo-dev
	libx11-dev
	libxext-dev
	libxrandr-dev
	libxrender-dev
	libxt-dev
	libxtst-dev
"
depends=""
subpackages="$pkgname-jre:_jre"
source="https://github.com/adoptium/temurin21-binaries/releases/download/jdk-$_pkgvername/OpenJDK21u-jre_${CARCH/x86_64/x64}_alpine-linux_hotspot_$_pkgver.tar.gz"

_java_home="/usr/lib/jvm/java-21-temurin-jre"

ldpath="$_java_home/lib:$_java_home/lib/server"
sonameprefix="$pkgname:"

prepare() {
	default_prepare
}

check() {
	local _java_bin="./jdk-$_pkgverplus-jre/bin"

	# 1) check that java -version works
	$_java_bin/java -version
}

package() {
	mkdir -p "$pkgdir/$_java_home"
	cp -r "$srcdir"/jdk-"$_pkgverplus-jre"/* "$pkgdir/$_java_home"
}

_jre() {
	pkgdesc="Eclipse Temurin 21 (JRE)"
	provides="java-jre"
	depends="java-common java-cacerts"
	_fromroot="$pkgdir/$_java_home"
	_toroot="$subpkgdir/$_java_home"

	mkdir -p "$_toroot"
	mv "$_fromroot/bin"     "$_toroot"
	mv "$_fromroot/conf"    "$_toroot"
	mv "$_fromroot/legal"   "$_toroot"
	mv "$_fromroot/lib"     "$_toroot"
	mv "$_fromroot/release" "$_toroot"
	mv "$_fromroot/NOTICE"  "$_toroot"

	# symlink to shared cacerts store
	rm "$_toroot/lib/security/cacerts"
	ln -sf /etc/ssl/certs/java/cacerts \
		"$_toroot/lib/security/cacerts"
}

case "$CARCH" in
	x86_64)
		_arch_sum="a8fcc43927664ba191c9a77d1013f1f32fec1acc22fe6f0c29d687221f2cc95d"
		;;
	aarch64)
		_arch_sum="2898ea1ddf6f70f09b09cf99d928f6d4c862f78f81104f5dce3e44a832b8444a"
		;;
esac

sha256sums="
$_arch_sum  OpenJDK21u-jre_${CARCH/x86_64/x64}_alpine-linux_hotspot_$_pkgver.tar.gz
"
